package action;

import entity.category;
import entity.tea;
import org.apache.struts2.ServletActionContext;
import com.baizhi.service.impl.teaServiceImpl;
import com.baizhi.service.teaService;
import util.PageBean;

import javax.servlet.http.HttpSession;
import java.util.ArrayList;
import java.util.List;

public class teaAction {
    private PageBean<tea> p=new PageBean<tea>();
    private String name;
    private tea t=new tea();
    private List<category> findoption=new ArrayList<>();
    private int id;

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public List<category> getFindoption() {
        return findoption;
    }

    public void setFindoption(List<category> findoption) {
        this.findoption = findoption;
    }

    public tea getT() {
        return t;
    }

    public void setT(tea t) {
        this.t = t;
    }

    public PageBean<tea> getP() {
        return p;
    }

    public void setP(PageBean<tea> p) {
        this.p = p;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String page(){
        teaService  a=new teaServiceImpl();
        p = a.page(p, name);
        System.out.println(p);
        return "page";
    }
    public String insert(){
        teaService a=new teaServiceImpl();
        a.add(t);
        System.out.println(t);
        return "addsucess";
    }
    public String cate(){
        teaService a=new teaServiceImpl();
        findoption = a.findoption();
        return  "findsucess";
    }
    public String deletes(){
        teaService a=new teaServiceImpl();
        a.delete(id);
        return "desucess";
    }
    public String moren(){
        teaService a=new teaServiceImpl();
        HttpSession session = ServletActionContext.getRequest().getSession();
        int c = (int) session.getAttribute("id");
        t = a.findone(c);
        System.out.println(t);
        return "morens";
    }
    public String moren1(){
        teaService a=new teaServiceImpl();
        List<category> list = a.findoption();
        System.out.println(list);
        HttpSession session = ServletActionContext.getRequest().getSession();
        session.setAttribute("list", list);
        session.setAttribute("id",id);
        return "moren11";
    }
    public String update(){
        teaService a=new teaServiceImpl();
        a.update(t,id);
        return "updates";
    }
}
